package com.sky.controller.admin;


import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 管理端控制器
 * </p>
 *
 * @since 2023-04-24
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端-订单接口")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 完成订单（修改订单状态）
     *
     * @param id
     * @return zhongweiwei
     */
    @PutMapping("complete/{id}")
    @ApiOperation("完成订单")
    public Result CompleteOrder(@PathVariable Long id) {
        log.info("完成订单");
        ordersService.CompleteOrder(id);
        return Result.success();
    }

    /**
     * 取消订单
     * zhongweiwei
     */
    @ApiOperation("取消订单")
    @PutMapping("cancel")
    public Result CancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        log.info("取消订单{}", ordersCancelDTO);
        ordersService.CancelOrder(ordersCancelDTO);
        return Result.success();

    }

    /**
     * zhongweiwei
     * 拒绝订单
     * @param ordersRejectionDTO
     * @return
     */
    @ApiOperation("拒绝订单")
    @PutMapping("rejection")
public  Result rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("拒绝订单{}",ordersRejectionDTO);
        ordersService.rejectionOrder(ordersRejectionDTO);
        return Result.success();

    }

    /**
     * zhongweiwei
     * 接单
     * @param ordersConfirmDTO
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("confirm")
    public  Result confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("接单{}",ordersConfirmDTO);
        ordersService.confirmOrder(ordersConfirmDTO);
        return Result.success();

    }

    /**
     * zhongweiwei
     * @param ordersConfirmDTO
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("delivery")
    public  Result deliveryOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("派送订单{}",ordersConfirmDTO);
        ordersService.deliveryOrder(ordersConfirmDTO);
        return Result.success();

    }
    /**
     * zhongweiwei
     *
     * @return 统计各个状态的订单数量
     */
    @ApiOperation("统计各个状态的订单数量")
    @GetMapping("statistics")
    public Result<OrderStatisticsVO> statisticsOrder() {
        log.info("统计各个状态的订单数量{}" );
        OrderStatisticsVO orderStatisticsVO=ordersService.statisticsOrder();
return Result.success(orderStatisticsVO);
    }
@ApiOperation("分页查询")
    @GetMapping("conditionSearch")
    public Result conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("分页查询{}",ordersPageQueryDTO);
    PageResult pageResult =ordersService.page(ordersPageQueryDTO);
    return Result.success(pageResult);

}

    /**
     * 查询订单详情
     * zhongweiwei
     * @param id
     * @return
     */
    @ApiOperation("查询订单详情")
    @GetMapping("details/{id}")
    public Result<OrderVO> detailsOrder(@PathVariable Long id){
        log.info("查询订单详情{}",id);
        OrderVO orderVO=  ordersService.detailsOrder(id);
        return Result.success(orderVO);

    }





}
